<!--
@license
Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<div *ngIf="isGroupExpanded">
  <ng-container
    *ngTemplateOutlet="groupControls; context: {isBottomControl: false}"
  ></ng-container>

  <div class="card-grid" [style.grid-template-columns]="gridTemplateColumn">
    <div
      *ngFor="let item of cardIdsWithMetadata; trackBy: trackByCards"
      class="card-space"
      [ngClass]="{
          'full-width': cardsAtFullWidth.has(item.cardId) || cardStateMap[item.cardId]?.fullWidth,
          'full-height': cardsAtFullHeight.has(item.cardId) || cardStateMap[item.cardId]?.tableExpanded
        }"
    >
      <card-view
        [cardId]="item.cardId"
        [groupName]="groupName"
        [pluginType]="item.plugin"
        [cardObserver]="cardObserver"
        [cardLazyLoader]="item.cardId"
        (fullWidthChanged)="onFullWidthChanged(item.cardId, $event)"
        (fullHeightChanged)="onFullHeightChanged(item.cardId, $event)"
      >
      </card-view>
    </div>
  </div>

  <ng-container
    *ngTemplateOutlet="groupControls; context: {isBottomControl: true}"
  ></ng-container>
</div>

<ng-template #groupControls let-isBottomControl="isBottomControl">
  <div class="group-controls" *ngIf="showPaginationControls">
    <span class="prev-container">
      <button
        *ngIf="showPaginationControls"
        class="prev pagination-button"
        mat-button
        i18n-aria-label="A button that sets a group to the previous page."
        aria-label="Previous page"
        [disabled]="pageIndex === 0"
        (click)="handlePageChange(pageIndex - 1, $event.target)"
      >
        Previous
      </button>
    </span>

    <span class="input-and-next-container">
      <span *ngIf="showPaginationControls">
        <span
          *ngIf="showPaginationInput(isBottomControl)"
          class="pagination-input"
          ><input
            [value]="pageIndex + 1"
            type="number"
            min="1"
            [max]="numPages"
            (input)="onPaginationInputChange($event)"
            (change)="onPaginationInputChange($event)"
          />
          of {{ numPages }}</span
        >
        <button
          mat-button
          i18n-aria-label="A button that sets a group to the next page."
          aria-label="Next page"
          class="next pagination-button"
          [disabled]="pageIndex + 1 >= numPages"
          (click)="handlePageChange(pageIndex + 1, $event.target)"
        >
          Next
        </button>
      </span>
    </span>
  </div>
</ng-template>
